// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

func dominantIndex(array []int) int {
	highest, secHighest := 0, 0
	key := 0
	for k, v := range array {
		if v > highest {
			secHighest = highest
			highest = v
			key = k
		} else if v > secHighest {
			secHighest = v
		}
	}

	if 2*secHighest <= highest {
		return key
	} else {
		return -1
	}
}

func main() {
	points := []int{2, 10, 5, 1}
	res := dominantIndex(points)
	fmt.Println(res)
}

//$ go run interview6-1.go
//1
